Fix return-code checking in tools.
Signed-off-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
return ret;
}
-/* this is a function which can go away. It dumps a hunk of
- * guest pages to a file (/tmp/dumpit); handy for debugging
- * your image builder.
- * Xen guys, nuke this if you wish.
- */
-void
-dumpit(int xc_handle, u32 dom,
- int start_page, int tot, unsigned long *page_array)
-{
- int i, ofd;
- unsigned char *vaddr;
-
- ofd = open("/tmp/dumpit", O_RDWR);
- for (i = start_page; i < tot; i++) {
- vaddr = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
- PROT_READ | PROT_WRITE,
- page_array[i]);
- if (!vaddr) {
- fprintf(stderr, "Page %d\n", i);
- perror("shit");
- read(0, &i, 1);
- return;
- }
- write(ofd, vaddr, 4096);
- munmap(vaddr, PAGE_SIZE);
- }
-}
int
blah(char *b)
{
unsigned long sz;
lseek(fd, 0, SEEK_SET);
- read(fd, &sig, sizeof(sig));
+ if ( read(fd, &sig, sizeof(sig)) != sizeof(sig) )
+ return 0;
sz = lseek(fd, 0, SEEK_END);
if ( sig == 0x8b1f ) /* GZIP signature? */
{
lseek(fd, -4, SEEK_END);
- read(fd, &_sz, 4);
+ if ( read(fd, &_sz, 4) != 4 )
+ return 0;
sz = _sz;
}
lseek(fd, 0, SEEK_SET);
goto out;
}
- *size = xc_get_filesz(kernel_fd);
+ if ( (*size = xc_get_filesz(kernel_fd)) == 0 )
+ {
+ PERROR("Could not read kernel image");
+ goto out;
+ }
if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL )
{
printf ("numItems: %d\n", numItems);
mem_map.nr_map = numItems;
-
/* should raise an error here. */
if (numItems < 0) return NULL; /* Not a list */
-
/* iterate over items of the list, grabbing ranges and parsing them */
for (i = 1; i <= numItems; i++) { // skip over "memmap"
PyObject *item, *f1, *f2, *f3, *f4;
sf2 = PyString_AsString(f2);
lf3 = PyLong_AsLong(f3);
lf4 = PyLong_AsLong(f4);
- sscanf(sf1, "%lx", &lf1);
- sscanf(sf2, "%lx", &lf2);
+ if ( sscanf(sf1, "%lx", &lf1) != 1 )
+ return NULL;
+ if ( sscanf(sf2, "%lx", &lf2) != 1 )
+ return NULL;
mem_map.map[i-1].addr = lf1;
mem_map.map[i-1].size = lf2 - lf1;
*/
void write_rec(unsigned int cpu, struct t_rec *rec, FILE *out)
{
- fwrite(&cpu, sizeof(cpu), 1, out);
- fwrite(rec, sizeof(*rec), 1, out);
+ size_t written = 0;
+ written += fwrite(&cpu, sizeof(cpu), 1, out);
+ written += fwrite(rec, sizeof(*rec), 1, out);
+ if ( written != 2 )
+ {
+ PERROR("Failed to write trace record");
+ exit(EXIT_FAILURE);
+ }
}
/**